{extend name=".././view/create.html" /}
{block name="jscss"}
<style>
/*mycheckbox
{
    style:{
      padding-left: 10px;
      padding-right: 10px;
  };
}*/
</style>

{/block}
{block name="form"}
    <form class="layui-form layui-form-pane" lay-filter="myform">
          <div class="layui-form-item">
              <label for="title" class="layui-form-label">
                  <span class="x-red">*</span>角色名称
              </label>
              <div class="layui-input-block">
                  <input type="text" id="title" name="title" lay-verify="required"
                  autocomplete="off" class="layui-input " value="{$list.data.title|default=''}" placeholder="中文2-25个字符">
              </div>
          </div>
          <div class="layui-form-item" >
              <label for="miaoshu" class="layui-form-label">
                  <span class="x-red">*</span>角色描述
              </label>
              <div class="layui-input-block">
                  <input type="text" id="miaoshu" name="miaoshu" lay-verify="required"
                  autocomplete="off" class="layui-input " value="{$list.data.miaoshu|default=''}" placeholder="中文2-25个字符">
              </div>
          </div>
          <div class="layui-form-item" id="rule" style="background: #eeeeee">
          </div>
          <div class="layui-form-item" style="text-align: right;">
              <button  class="layui-btn" lay-filter="mysubmit" lay-submit="">
                  {$list.set.butname}
              </button>
          </div>
    </form>
{/block}

{block name="myjs"}
    <script type="text/javascript">
      // 监测复选框按钮
      layui.use(['form'], function(){
        var form = layui.form;
        // 加载权限
        auth = <?php echo json_encode($list['auth']);?>;
        auth = eval(auth);
        createCheckbox(auth,0);

        // 创建权限按钮
        function createCheckbox(arr,pid)
        {

          if(arr.length==0)
          {
            return false;
          }

          // 创建div
          if(pid == 0)
          {
            mydiv = "<div class='layui-form-item' id='p"+pid+"'></div>";
            $('#rule').append(mydiv);
          }else{
            mydiv = "<div class='layui-form-item' style='margin-left: 3%; overflow:auto' id='p"+pid+"'></div>";
            $('#'+pid).after(mydiv);
          }
          // 创建checkbox
          for(var i in arr){
            if(arr[i].select == true)
            {
              mycheckbox = '<input type="checkbox" name="rules[]" title="'+arr[i].title+'" value="'+arr[i].id+'" lay-skin="primary" lay-filter="auth" lay-verify="required" id ="'+arr[i].id+'" pid="'+arr[i].pid+'" checked>';
            }else{
              mycheckbox = '<input type="checkbox" name="rules[]" title="'+arr[i].title+'" value="'+arr[i].id+'" lay-skin="primary" lay-filter="auth" lay-verify="required" id ="'+arr[i].id+'" pid="'+arr[i].pid+'">';
            }

            $('#p'+pid).append(mycheckbox);
            createCheckbox(arr[i].child,arr[i].id);
          }

          form.render();
        }
      });
    </script>
{/block}

